<template>
    <div>
        <h3>添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">药品名称</td>
                    <td>
                        <input type="text" v-model="querinfo.Name">
                    </td>
                </tr>

                <tr>
                    <td align="right">药品名称</td>
                    <td>
                        <input type="file" @change="img">
                        <img :src="querinfo.Photo" width="150" height="100">
                    </td>
                </tr>

                <tr>
                    <td align="right">科室</td>
                    <td>
                        <select v-model="querinfo.OfficeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.list">{{ item.Name }}</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td align="right">用药日期</td>
                    <td>
                        <input type="date" v-model="querinfo.CreateTime">
                    </td>
                </tr>

                <tr>
                    <td align="right">病人姓名</td>
                    <td>
                        <input type="text" v-model="querinfo.PeopleName">
                    </td>
                </tr>

                <tr>
                    <td align="right">病房号码</td>
                    <td>
                        <input type="text" v-model="querinfo.Number">
                    </td>
                </tr>

                <tr>
                    <td align="right">用药状态</td>
                    <td>
                        <input type="radio" :value="1" v-model="querinfo.State">未开始
                        <input type="radio" :value="0" v-model="querinfo.State">已完成
                    </td>
                </tr>

                <tr>
                    <td align="right">服务</td>
                    <td>
                        <input type="checkbox" value="满分" v-model="querinfo.Fuwu">满分
                        <input type="checkbox" value="完美" v-model="querinfo.Fuwu">完美
                        <input type="checkbox" value="舒服" v-model="querinfo.Fuwu">舒服
                    </td>
                </tr>

                <tr>
                    <td align="right">配药医生</td>
                    <td>
                        <input type="text" v-model="querinfo.Yisheng">
                    </td>
                </tr>

                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="添加" @click="ok" class="btn btn-primary">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,reactive,onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
const route=useRoute();
const router=useRouter();
let data:any=reactive({
    list:[]
})


const querinfo:any=reactive({
  "Name": "",
  "Photo": "string",
  "OfficeId": "",
  "CreateTime": "",
  "PeopleName": "",
  "Number": "",
  "State": "",
  "Fuwu": [],
  "Yisheng": "",
})

onMounted(()=>{
    getoffice();
})

const ok=()=>{
    querinfo.Fuwu=querinfo.Fuwu.toString();
    axios({
        method:"post",
        url:"/api/Month/AddYao",
        data:querinfo
    })
    .then(res=>{
        if(res.data==-1){
            alert('名称重复')
        }
        else if(res.data>0){
            alert('添加成功')
        }
        else{
            alert('添加失败')
        }
    })
}

const img=(e:any)=>{
    var s=e.target.files[0];
    var d=new FormData();
    d.append('file',s);
    axios({
        method:"post",
        url:"/api/Month/Img",
        data:d
    })
    .then(res=>{
        if(res.data=="格式错误"){
            alert('格式错误')
        }
        else if(res.data=="超过2MB"){
            alert("超过2MB")
        }
        else{
            querinfo.Photo=res.data
        }
    })
}

const getoffice=()=>{
    axios({
        method:"get",
        url:"/api/Month/ShowOffice"
    })
    .then(res=>{
        console.log(res)
        data.list=res.data;
    })
    .catch(err=>{
        console.log(err);
    })
}


</script>



<style scoped>

</style>